<?php
/*
	
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('action'=>'/dayusetting/','title'=>'基本设置'),
	array('action'=>'/dayulog/','title'=>'短信日志'),
	array('action'=>'/test/','title'=>'前往测试'),
);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	if($_SESSION['uniacid']==1){
		$params=array('uniacid'=>array(0,1));
	}else{
		$params=array('uniacid'=>$_SESSION['uniacid']);
	}	
	if(!empty($_RQ['p'])){
		$params['plugin']=trim($_RQ['p']);
		$return['params']['p']=$_RQ['p'];
	}if(!empty($_RQ['mb_id'])){
		$params['mb_id']=trim($_RQ['mb_id']);
		$return['params']['mb_id']=$params['mb_id'];
	}
	$fields=array('id','plugin','mb_id','status','remake','createtime','mobile');
	$parameter=array('params'=>$params,'limit'=>array($pindex,$psize),'fields'=>$fields,'orderby'=>'id desc');
	$list=$this->get_list('dayu_log',$parameter,$total);
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array (
		  'type' => 'list',
		  'tabs'=>$tabs,
		  'list' => 
		  array (
		    'data' => 'list',
			'edit'=>false,
		    'list' => 
		    array (
		      0 => 
		      array (
		        'type' => 'string',
		        'name' => 'id',
		        'title' => 'ID',
		      ),
		      1 => 
		      array (
		        'name' => 'plugin',
		        'type' => 'string',
		        'title' => '调用插件',
		      ),
		      2 => 
		      array (
		        'name' => 'mb_id',
		        'type' => 'string',
		        'title' => '模板id',
		      ),
			  3 => 
		      array (
		        'name' => 'mobile',
		        'type' => 'string',
		        'title' => '手机号码',
		      ),
		      4 => 
		      array (
		        'name' => 'status',
		        'type' => 'radio',
		        'title' => '发送状态',
		        'options' => 'status_xuanxiang',
		      ),
		      5=> 
		      array (
		        'name' => 'remake',
		        'type' => 'string',
		        'title' => '详情',
		      ),
		      6 => 
		      array (
		        'type' => 'time',
		        'name' => 'createtime',
		        'title' => '创建时间',
		      ),
		    ),
		  ),
		  'search' => 
		  array (
		    0 => 
		    array (
		      'name' => 'p','width'=>15,
		      'type' => 'string',
		      'title' => '调用插件',
		    ),
		    1 => 
		    array (
		      'name' => 'mb_id','width'=>15,
		      'type' => 'string',
		      'title' => '模板id',
		    ),
		  ),
		);
$return['status_xuanxiang']=array (
  0 => '失败',
  1 => '成功',
);

	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=$this->get('dayu_log',array('id'=>$id));

	}else{
		$item=array();
	}
	$return['item']=$item;
	$return['htmls']=array (
  'type' => 'edit',
  'post' => 'post',
  'edit_tab' => NULL,
  'edits' => 
  array (
  ),
);

	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array_fields(array(),$post);

	$id=intval($post['id']);
	if($id){
		$this->update('dayu_log',$data,array('id'=>$id));
		exi('修改dayu_log成功！');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		$this->insert('dayu_log',$data);
		exi('新增dayu_log成功！');
	}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		$this->delete('dayu_log',array('id'=>$id));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->delete('dayu_log',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}